//食物的生成
class Food{
    constructor(select){
        this.map=document.querySelector(select)
        
        //创建食物
        this.food=document.createElement("div")
        //定义样式
        this.food.className="food"
        //坐标
        this.map.appendChild(this.food)

        this.x=0
        this.y=0

        this.foodPos()
    }
    //随机坐标
    foodPos(){
        // console.log(this.map.clientWidth/21)
        // console.log(this.map.clientHeight/21)

        const w_nub=this.map.clientWidth/21
        const h_nub=this.map.clientHeight/21

        let n1=Math.floor(Math.random()*w_nub)
        let n2=Math.floor(Math.random()*h_nub)
        // console.log(n1,n2)

        this.x=n1*21
        this.y=n2*21
        console.log(this.x,this.y)

        this.food.style.left=this.x+"px"
        this.food.style.top=this.y+"px"
    }
}